<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let str = function (s, t) {
      let fn = (str) => {
        const res = [];
        for (const a of str) {
          // 如果等于 # 就进栈 否则就出
          res[a === "#" ? 'pop' : 'push'](a)
        }
        return res.join('')
      }
      // 经处理 判断 s  === t 是否相同
      return str[s] === str[t]
    }
    console.log(str('ab#c', 'ad#c'))

    let fnNum = (num) => {
      var len = 0
      for (var i = 0; i < num.length; i++) {
        len += num[i]
        i++
      }
      let arrt = new Array(len)
      let cont = 0
      for (var i = 0; i < num.length; i++) {
        for (var j = 0; j < num[i]; j++) {
          arrt[cont++] = num[i + 1]
        }
        i++
      }
      return arrt
    }
    console.log(fnNum([1, 2, 3, 4]))

    var three = (n) => {
      for (var i = 1; i < n; i++) {
        if (String(i).indexOf('0') === -1 && String(n - i).indexOf('0') === -1) {
          return [i, n - i]
        }
      }
    }
    console.log(three(2))

    var theen = (num) => {
      var num = String(num).split('')
      for (var i = 0; i < num.length; i++) {
        if (num[i] === '6') {
          num[i] = '9'
          return num.join('')
        }
      }
      return num
    }
    console.log(theen(9669))

    var kWeakestRows = (mat, k) => {
      var arr = []
      for (var i = 0; i < mat.length; i++) {
        var ant = 0
        for (var j = 0; j < mat[i].length; j++) {
          if (mat[i][j]) {
            ant++
          }
        }
        arr.push([i, ant])
      }
      arr.sort((a, b) => a[1] - b[1])
      const res = []
      for (var i = 0; i < k; i++) {
        res.push(arr[i][0])
      }
      return res
    }
    console.log(kWeakestRows(mat =
      [[1, 0, 0, 0],
      [1, 1, 1, 1],
      [1, 0, 0, 0],
      [1, 0, 0, 0]],
      k = 2))

    var sortSentence = (s) => {
      s = s.split(' ')
      var arr = []
      s.forEach(font => {
        arr[font[font.length - 1] - 1] = font.slice(0, font.length - 1)
      });
      return arr.join(' ')
    }
    console.log(sortSentence("is2 sentence4 This1 a3"));

    var sen = (arr) => {
      var l = arr.length
      for (var i = 0; i < l; i++) {
        for (var j = 0; j < l; j++) {
          if ((i === j || i + j === l - 1) === !arr[i][j]) return false
        }
        return true
      }
    }
    console.log(sen([[5, 7, 0], [0, 3, 1], [0, 5, 0]]))

    var tend = (c) => {
      for (var i = 0; i * i < c; i++) {
        var j = Math.sqrt(c - i * i)
        if (j === parseInt(j)) {
          return true
        }
      }
      return false
    }
    console.log(tend(5))

    var one = (mass, arr) => {
      arr.sort((a, b) => a - b)
      for (const a of arr) {
        if (mass >= a) {
          mass += a
        } else return false
      }
      return true
    }
    console.log(one(10, [9, 3, 19, 5, 21]))

    var tow = (s, t) => {
      s = s.split(' ').sort().join(' ')
      t = t.split(' ').sort().join(' ')
      for (var i = 0; i < t.length; i++) {
        if (s[i] != t[i]) {
          return t[i]
        }
      }
    }
    console.log(tow('abcd', 'abcde'))
  </script>
</body>

</html>